import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:surfaceim/common/values/values.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:surfaceim/common/utils/utils.dart';

/// 普通圆角按钮
Widget primaryButtonWidget({
  required VoidCallback onPressed,
  bool disable = false,
  double width = 460,
  double height = 90,
  Color gbColor = AppColors.primaryElement,
  String title = "普通圆角按钮",
  Color fontColor = AppColors.primaryElementText,
  double fontSize = 32,
  String fontName = "Montserrat",
  FontWeight fontWeight = FontWeight.w700,
}) {
  gbColor = disable ? AppColors.disableElement : AppColors.primaryElement;
  return Container(
    width: width.w,
    height: height.h,
    child: ElevatedButton(
      style: ButtonStyle(
        enableFeedback: true,

        // 按钮边框
        // side: MaterialStateProperty.all(
        //     BorderSide(width: 1, color: AppColors.primaryElementSecondary)),

        textStyle: MaterialStateProperty.all(TextStyle(
          fontSize: fontSize.sp,
        )),

        /// 阴影值
        // elevation: MaterialStateProperty.all(0),

        /// 高亮色
        overlayColor:
            MaterialStateProperty.all(AppColors.primaryElementSecondary),
        // overlayColor: MaterialStateProperty.resolveWith(
        //   (states) {
        //     print(states);
        //     return states.contains(MaterialState.pressed)
        //         ? AppColors.primaryElementSecondary
        //         : null;
        //   },
        // ),
        // 字体颜色
        // foregroundColor: MaterialStateProperty.resolveWith(
        //   (states) {
        //     if (states.contains(MaterialState.focused) &&
        //         !states.contains(MaterialState.pressed)) {
        //       return AppColors.thirdElementText;
        //     } else if (states.contains(MaterialState.pressed)) {
        //       return AppColors.thirdElementText;
        //     }
        //     return fontColor;
        //   },
        // ),
        backgroundColor: MaterialStateProperty.resolveWith((states) {
          // if (states.contains(MaterialState.pressed)) {
          //   return AppColors.primaryElementSecondary;
          // }
          return gbColor;
        }),
        shape: MaterialStateProperty.all(RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(height.h / 2)),
        )),
      ),
      child: Text(
        title,
        textAlign: TextAlign.center,
        style: TextStyle(
          color: fontColor,
          fontFamily: fontName,
          fontWeight: fontWeight,
          fontSize: fontSize.sp,
          // height: 1,
        ),
      ),
      onPressed: () {
        SinglePreventionData.throttle(() {
          //触摸收起键盘
          SystemChannels.textInput.invokeMethod('TextInput.hide');
          // 禁用状态判断
          if (!disable) {
            onPressed();
          } else {
            print('disable == true');
          }
        }, continueClick: () {});
      },
    ),
  );
}

/// 扁平圆角按钮
Widget btnFlatButtonWidget({
  required VoidCallback onPressed,
  double width = 140,
  double height = 40,
  Color gbColor = AppColors.primaryElement,
  String title = "button",
  Color fontColor = AppColors.primaryElementText,
  double fontSize = 14,
  String fontName = "Montserrat",
  FontWeight fontWeight = FontWeight.w400,
  BorderRadius? borderRadius
}) {
  return Container(
    width: width.w,
    height: height.h,
    child: ElevatedButton(
      style: ButtonStyle(
        enableFeedback: true,

        // 按钮边框
        // side: MaterialStateProperty.all(
        //     BorderSide(width: 1, color: AppColors.primaryElementSecondary)),

        textStyle: MaterialStateProperty.all(TextStyle(
          fontSize: 16.sp,
        )),

        /// 阴影值
        // elevation: MaterialStateProperty.all(0),

        /// 高亮色
        overlayColor:
            MaterialStateProperty.all(AppColors.primaryElementSecondary),
        // overlayColor: MaterialStateProperty.resolveWith(
        //   (states) {
        //     print(states);
        //     return states.contains(MaterialState.pressed)
        //         ? AppColors.primaryElementSecondary
        //         : null;
        //   },
        // ),
        // 字体颜色
        // foregroundColor: MaterialStateProperty.resolveWith(
        //   (states) {
        //     if (states.contains(MaterialState.focused) &&
        //         !states.contains(MaterialState.pressed)) {
        //       return AppColors.thirdElementText;
        //     } else if (states.contains(MaterialState.pressed)) {
        //       return AppColors.thirdElementText;
        //     }
        //     return fontColor;
        //   },
        // ),
        backgroundColor: MaterialStateProperty.resolveWith((states) {
          // if (states.contains(MaterialState.pressed)) {
          //   return AppColors.primaryElementSecondary;
          // }
          return gbColor;
        }),
        shape: MaterialStateProperty.all(RoundedRectangleBorder(
          borderRadius: borderRadius == null ? Radii.k6pxRadius : borderRadius,
        )),
      ),
      child: Text(
        title,
        textAlign: TextAlign.center,
        style: TextStyle(
          color: fontColor,
          fontFamily: fontName,
          fontWeight: fontWeight,
          fontSize: fontSize.sp,
          height: 1,
        ),
      ),
      onPressed: onPressed,
    ),
  );
}

/// 第三方按钮
Widget btnFlatButtonBorderOnlyWidget({
  required VoidCallback onPressed,
  double width = 88,
  double height = 44,
  required String iconFileName,
}) {
  return Container(
    width: width.w,
    height: height.h,
    child: TextButton(
      style: ButtonStyle(
        // textStyle: MaterialStateProperty.all(TextStyle(
        //   fontSize: 16.sp,
        // )),
        // foregroundColor: MaterialStateProperty.resolveWith(
        //   (states) {
        //     if (states.contains(MaterialState.focused) &&
        //         !states.contains(MaterialState.pressed)) {
        //       return Colors.blue;
        //     } else if (states.contains(MaterialState.pressed)) {
        //       return Colors.deepPurple;
        //     }
        //     return AppColors.primaryElementText;
        //   },
        // ),
        // backgroundColor: MaterialStateProperty.resolveWith((states) {
        //   if (states.contains(MaterialState.pressed)) {
        //     return Colors.blue[200];
        //   }
        //   return AppColors.primaryElement;
        // }),
        shape: MaterialStateProperty.all(RoundedRectangleBorder(
          borderRadius: Radii.k6pxRadius,
        )),
      ),
      child: Image.asset(
        "assets/images/icons-$iconFileName.png",
      ),
      onPressed: onPressed,
    ),
  );
}
